<template>
  <home-card title="常用功能" isDark>
    <el-row :gutter="16">
      <el-col :span="12" v-for="task in oftenList" :key="task.type">
        <div class="often-total">
          <div class="often-total-num">
            {{ task.num }}
          </div>
          <div class="often-total-title">
            <span>{{ task.title }}</span>
            <i
              class="el-icon-arrow-right often-total-desc"
              @click="goToCreate(task.type)"
            ></i>
          </div>
          <img :src="task.icon" :alt="task.type" class="often-total-icon" />
        </div>
      </el-col>
    </el-row>
  </home-card>
</template>

<script>
import { getAppPool } from "@/api/home";
import HomeCard from "./home-card.vue";
import formIcon from "../icons/form.png";
import processIcon from "../icons/process.png";

export default {
  components: { HomeCard },
  data() {
    return {
      oftenList: this.getOftenData(),
    };
  },
  created() {
    this.getTotalCount();
  },
  methods: {
    getTotalCount() {
      getAppPool().then(({ data }) => {
        this.oftenList = this.getOftenData(data);
      });
    },
    getOftenData(data) {
      return [
        {
          title: "启用中表单",
          type: "form",
          icon: "todo-info",
          num: data?.fromCount || 0,
          icon: formIcon,
        },
        {
          title: "发布中流程",
          type: "process",
          icon: "todo-success",
          num: data?.processCount || 0,
          icon: processIcon,
        },
      ];
    },
    goToCreate() {
      let path = "";
      let query = {};
      switch (this.currType) {
        case "form":
          path = "/bpm/manager/form";
          break;
        case "process":
          path = "bpm/manager/model";
          break;

        default:
          break;
      }
      this.$router.push({
        path,
        query,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.often-total {
  padding: 12px 12px 20px;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  &:hover {
    box-shadow: 0px 4px 8px 0px rgba(0, 0, 0, 0.08);
  }

  &-num {
    font-size: 24px;
    font-family: DIN Alternate-Bold, DIN Alternate;
    font-weight: bold;
    color: #1d2129;
    line-height: 28px;
  }
  &-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    z-index: 1;
    span {
      font-size: 12px;
      margin: 0;
      color: #1d2129;
      line-height: 20px;
    }
  }
  &-desc {
    margin-left: 6px;
    font-size: 20px;
    color: #0047ea;
    // background-color: #0047ea;
    // border-color: #0047ea;
  }
  &-icon {
    position: absolute;
    height: 40px;
    bottom: 0;
    left: 40px;
  }
}
</style>
